﻿#region License
//  Distrubted Under the GNU Public License version 2 (GPLv2)
// ========================================
// 
//  QuizzMasterStudio Version 3 
//  Copyright © 2012 , The Sparks (Autism App Jam 2014)
//  All rights reserved.  
// 
// Robert Long, Zephyr Yao, Hillary Chansavang, Li Xiao, Arial Xiao
// 
//  This program is free software: you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation, either version 3 of the License, or
//  (at your option) any later version.
//  
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//  
//  You should have received a copy of the GNU General Public License
//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
//  The full license is also included in the root folder.
// 
// Robert Long
//  Email: rbtLong@live.com
#endregion

using System;
using System.Collections.Generic;
using System.Windows.Media.Animation;
using Core.Util;

namespace Core.RandomMovements
{
    public abstract class RandomGestureBase
    {
        readonly List<Storyboard> _animations = new List<Storyboard>();
        readonly RangedTimer _tmr;
        readonly Random _rnd = new Random();

        protected RangedTimer AnimationTimer { get { return _tmr; }  }
        protected List<Storyboard> Animations { get { return _animations; }} 

        protected RandomGestureBase(IEnumerable<Storyboard> animations)
        {
            _animations = new List<Storyboard>(animations);
            _tmr.Tick += _tmr_Tick;
            _tmr = new RangedTimer(8251, 10000);
        }

        protected RandomGestureBase(
            IEnumerable<Storyboard> animations, int interval, int delta)
        {
            _animations = new List<Storyboard>(animations);
            _tmr = new RangedTimer(interval, delta);
            _tmr.Tick += _tmr_Tick;
        }


            void _tmr_Tick(object sender, EventArgs e)
            {
                PeriodoicGestureTriggered();
            }

        protected abstract void PeriodoicGestureTriggered();

        protected int RandomInt(int min, int max)
        {
            return _rnd.Next(min, max);
        }

        protected Storyboard GetRandomStoryboard()
        {
            var n = _rnd.Next(0, _animations.Count - 1);
            return _animations[n];
        }

        protected Storyboard GetRandomStoryboard(int min, int max)
        {
            var n = _rnd.Next(min, _animations.Count - 1);
            return _animations[n];
        }

        public virtual void Start()
        {
            _tmr.Start();
        }

        public virtual void Stop()
        {
            _tmr.Stop();
        }

    }
}
